import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    count :0,
    todos:[
      {id:1, text: '...', done: true},
      {id:1, text: '...', done: true}
    ]
  },
  mutations: {
    increment(state,count){
      state.count += count.count
    },
    decrement(state){
      state.count--
    }
  },
  actions: {
     actionsA({commit}){
      commit('increment',{count:10})
    },
     actionB({dispatch,commit}){
      return dispatch('actionsA').then(()=>{
        commit('decrement')
      })

    }

  },
  getters:{
    donetodobyid : (state)=>(id)=>{
      return state.todos.find(todo=>todo.id==id)
    }
  },
})
